import App from './App'

// #ifndef VUE3
import Vue from 'vue'

import uView from "uni_modules/uview-ui";
Vue.use(uView);

import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif

import Request from './common/request.js';
import Common from './common/common.js';
uni.$req = new Request();
uni.$common = new Common();

if(process.env.NODE_ENV === "development") {
	// uni.baseUrl = "http://192.168.18.99:10087";
	// uni.baseUrl = "http://124.70.103.118:10087";
	uni.baseUrl = "https://famen.weizhongcloud.com";
} else {
	// uni.baseUrl = "http://192.168.18.99:10087";
	// uni.baseUrl = "http://124.70.103.118:10087";
	uni.baseUrl = "https://famen.weizhongcloud.com";
}

uni.addInterceptor('request',{
	invoke(args){
		args.url = uni.baseUrl + args.url;
		args.header.Authorization = uni.getStorageSync("token");
		args.header['Request-Source'] = "APP";
	},
	success(args){
		if(args.data.code === '4001'){
			let pages = getCurrentPages();
			let currentPage = pages[pages.length - 1].route;
			if(currentPage.includes("pages/login")) return ;
			uni.showToast({
				title: args.data.message,
				icon: "none"
			});
			uni.clearStorage();
			uni.$emit('initIm');
			uni.reLaunch({
				url: "/pages/login/login"
			});
		} else if(args.data.code === '5000'){
			uni.showToast({
				title: args.data.message,
				icon: "none"
			})
		}
	}
});
uni.addInterceptor('uploadFile',{
	invoke(args){
		if(args.url.indexOf("http") === -1){
			args.url = uni.baseUrl + args.url;
		}
	}
});
